*-------------------------------------------------------------------------------
* Price and Wasserman (2024), "The Summer Drop in Female Employment"
*
* Description: Set up project globals, adopaths, programs, and configurations.
*-------------------------------------------------------------------------------


* Initial configuration
*-------------------------------------------------------------------------------

* Specify Stata version on which code was developed and tested
version 15.1

* Reset programs and settings
discard
clear all

* Configure settings
set varabbrev off
set more off
set maxvar 32000
set matsize 11000


* Determine location of project folder
*-------------------------------------------------------------------------------

* Verify that this script is being run from within the "code" directory
assert substr("`c(pwd)'", -5, .) == "/code"

* Set the project directory
global basepath `=substr("`c(pwd)'", 1, length("`c(pwd)'") - 5)'
assert "$basepath" != ""

* Specify location of font files
global fontdir "$basepath/libraries/fonts"


* Specify names of IPUMS extracts (to be updated by users)
*-------------------------------------------------------------------------------

global cps_bms       "cps_00045"
global cps_asec      "cps_00044"
global atus_person   "atus_00015"
global atus_activity "atus_00014"


* Set up adopath and install/update .ado files
*-------------------------------------------------------------------------------

* Remove personal directories from the adopath
capture adopath - PERSONAL
capture adopath - PLUS
capture adopath - OLDPLACE

* Add custom commands and graphics files to the adopath
quietly adopath + "$basepath/libraries"
quietly adopath + "$basepath/libraries/ado"
quietly adopath + "$basepath/libraries/ado/custom"
quietly adopath + "$basepath/libraries/ado/ssc"
quietly adopath + "$basepath/libraries/schemes"

* Force Stata to search only the project directory for "personal" ado files
sysdir set PERSONAL "$basepath/libraries"

* If requested via command-line argument: install SSC packages
if "`1'" == "--install-ados" {
	* Store SSC packages within the project directory
	capture confirm file "$basepath/libraries/ado/ssc/"
	if _rc != 0 {
		mkdir "$basepath/libraries/ado/ssc/"
	}

	net set ado "$basepath/libraries/ado/ssc"

	* Install SSC packages
	ssc install addplot, replace
	ssc install coefplot, replace
	ssc install estout, replace
	ssc install filelist, replace
	ssc install ftools, replace
	ssc install freduse, replace
	ssc install gzsave, replace
	ssc install ipfraking, replace
	ssc install ivreg2, replace
	ssc install labutil, replace
	ssc install ranktest, replace
	ssc install regsave, replace
	ssc install shp2dta, replace
	ssc install spmap, replace
	ssc install xlincom, replace

	* Install gtools suite
	ssc install gtools, replace

	* Install non-SSC packages
	net install grc1leg, from(https://www.stata.com/users/vwiggins) replace
}

* Update gtools (https://github.com/mcaceresb/stata-gtools/issues/61)
mata: mata mlib index


* Define subroutines to automate logging and reset settings
*-------------------------------------------------------------------------------

* Clear memory and initialize the log file
capture program drop launch
program define launch
	* Specify the relative filepath within $basepath/[subdir]/...
	syntax, path(string)

	* Reset memory, without discarding .ado files
	clear
	clear results
	clear matrix
	estimates clear

	* Create model subdirectory for analytical scripts
	if substr("`path'", 1, 5) == "share" {
		capture mkdir "$basepath/models/`=substr("`path'", 7, .)'"
	}

	* Initialize subordinate log file
	capture log close sublog
	log using "$basepath/logs/`path'.log", name(sublog) text replace
end

* Close the log file
capture program drop unlaunch
program define unlaunch
	capture log query sublog
	if _rc == 0 log close sublog
end


* Customize graphics
*-------------------------------------------------------------------------------

* Specify default colors in RGB format
global col1 `""000 139 188""' // blue
global col2 `""228 109 010""' // orange
global col3 `""000 176 080""' // green
global col4 `""150 079 142""' // purple
global col5 `""215 215 000""' // yellow
global col6 `""175 175 175""' // gray

* Specify colors used for grayscale
global dkgs "gs8"
global ltgs "gs15*1.03"

* Specify line patterns used in plotting series
global pat1 "solid"
global pat2 "solid"
global pat3 "solid"
global pat4 "solid"
global pat5 "solid"
global pat6 "solid"

* Specify marker styles used in plotting series
global sym1 "circle"
global sym2 "triangle"
global sym3 "diamond"
global sym4 "square"
global sym5 "plus"
global sym6 "x"

* Set graph appearance, inclusive of above settings
set scheme spartan


* Set substantive parameters
*-------------------------------------------------------------------------------

* Newey-West bandwidth used to allow for serial correlation
global bandwidth = 27
